package com.zxy.ziems.server.device.controller;

import com.zxy.ziems.server.device.pojo.dto.DeviceTypePropertyDTO;
import com.zxy.ziems.server.device.pojo.vo.DataTypeVO;
import com.zxy.ziems.server.device.pojo.vo.DevicePropertyVO;
import com.zxy.ziems.server.device.service.DeviceTypePropertyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.DataType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 采集管理-设备类型配置属性
 * @author 10348359
 * @create 2024-03-20 16:53
 */
@RestController
@Validated
@RequestMapping("/api")
public class DeviceTypePropertyController {
    /**
     * 设备类型新增属性定义
     * @param dto 用户post参数
     * @return
     */
    @PostMapping("/device/type/property/add")
    public void add(@Validated(value = DeviceTypePropertyDTO.Add.class) @RequestBody DeviceTypePropertyDTO dto) throws Exception {
        service.add(dto);
    }

    /**
     * 设备类型更新属性定义
     * @param dto 用户post参数
     * @return
     */
    @PostMapping("/device/type/property/update")
    public void update(@Validated(value = DeviceTypePropertyDTO.Update.class) @RequestBody DeviceTypePropertyDTO dto) throws Exception {
        service.update(dto);
    }

    /**
     * 设备类型删除属性定义
     * @param dto 用户post参数
     * @return
     */
    @PostMapping("/device/type/property/delete")
    public void delete(@Validated(value = DeviceTypePropertyDTO.Delete.class) @RequestBody DeviceTypePropertyDTO dto) throws Exception {
        service.deleteById(dto.getId());
    }

    /**
     * 设备类型查询属性列表
     * @param deviceType 设备类型Code
     * @return
     */
    @GetMapping("/device/type/property/list")
    public List<DevicePropertyVO> list(@RequestParam(value = "deviceType", required = true) String deviceType) throws Exception {
        return service.viewListByDeviceType(deviceType);
    }

    /**
     * 查询指定设备类型的数据类型列表
     * @param deviceType 设备类型Code
     * @return
     */
    @GetMapping("/device/type/property/dataTypeList")
    public List<DataTypeVO> dataTypeList(@RequestParam(value = "deviceType", required = true) String deviceType) throws Exception {
        return service.viewDataTypeListByDeviceType(deviceType);
    }

    /**
     * 查询指定设备id的数据类型列表
     * @param deviceId 设备id
     * @return
     */
    @GetMapping("/device/property/dataTypeList")
    public List<DataTypeVO> dataTypeListByDevId(@RequestParam(value = "deviceId", required = true) String deviceId) throws Exception {
        return service.viewDataTypeListByDeviceId(deviceId);
    }

    private DeviceTypePropertyService service;

    @Autowired
    public void setService(DeviceTypePropertyService deviceTypePropertyService) {
        this.service = deviceTypePropertyService;
    }
}
